package com.bangbang.controller;


import com.bangbang.configresult.Result;
import com.bangbang.configresult.ResultEnum;
import com.bangbang.pojo.TbTeacher;
import com.bangbang.service.ITbTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 教室信息表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-11
 */
@RestController
@RequestMapping("/bangbang/tbTeacher")
@Api("教师管理服务接口")
public class TbTeacherController {

    @Autowired
    private ITbTeacherService tbTeacherService;

    @GetMapping
    @ApiOperation(value = "所有教师")
    public List<TbTeacher> list(){
        List<TbTeacher> list = tbTeacherService.list(null);
        return list;
    }

    @PostMapping
    @ApiOperation(value = "增加教师")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teacher", value = "用户实体类", required = true,paramType = "body"),
    })
    public Result save(@RequestBody TbTeacher teacher){
        boolean b = tbTeacherService.save(teacher);
        if(b){
            return Result.buildResult(ResultEnum.SUCCESS);
        }
        return Result.buildResult(ResultEnum.ERROR);
    }

    @DeleteMapping
    @ApiOperation("删除教师")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teaId",value = "教师ID", required = true,paramType = "query")
    })
    public Result delete(@RequestParam(required=true)Long teaId){
        boolean b = tbTeacherService.removeById(teaId);
        if(b){
            return Result.buildResult(ResultEnum.SUCCESS);
        }
        return Result.buildResult(ResultEnum.ERROR);
    }

    @PutMapping
    @ApiOperation("修改教师信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "teaId",value = "教师ID", required = true,paramType = "query"),
            @ApiImplicitParam(name = "teacher", value = "用户实体类", required = true,paramType = "body"),
    })
    public Result updateById(@RequestParam(required = true)Long teaId,@RequestBody TbTeacher teacher){
        teacher.setTeaId(teaId);
        boolean b = tbTeacherService.updateById(teacher);
        if(b){
            return Result.buildResult(ResultEnum.SUCCESS);
        }
        return Result.buildResult(ResultEnum.ERROR);
    }
}

